<template>
	<view class="team">
		<!-- #ifdef H5 -->
		<u-navbar back-icon-color="#fff" title="我的好友" title-color="#fff" :background="background"
			:border-bottom="false"></u-navbar>
		<!-- #endif -->

		<!-- 导航 -->
		<view class="tabs-box1">
			<u-tabs :activeStyle="{color:'#f29100'}" :list="list" :scrollable="false" :current="current"
				@change="clitbs"></u-tabs>
		</view>

		<!-- 列表 -->
		<view class="page-box">
			<!-- 有订单的情况 -->
			<view class="tb1 flex justify-around align-center">
				<view>好友信息</view>
				<view>注册时间</view>
			</view>
			<u-list pagingEnabled enableFlex >
				<u-list-item v-for="(item, index) in dataList" :key="index" class="flex justify-between align-center">
					<u-cell>
						<u-avatar slot="icon" shape="square" size="50" :src="item.avatar"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
						<view class="u-m-l-10" slot="title">
							<view class="usertitle ellipsis u-font-16">{{item.nickName}}</view>
							<view class="userid">ID: {{item.userId}}</view>
						</view>
						<view class="usertime u-font-13" slot="right-icon">
							{{item.createdAt}}
						</view>
					</u-cell>
				</u-list-item>
			</u-list>
			<!-- <view class="team_content flex justify-between align-center" v-for="(item, index) in dataList"
				:key="res.id">
				<view class="tm_left flex justify-start align-center">
					<view>
						<image :src="item.avatar" mode=""></image>
					</view>
					<view class="u-m-l-20">
						<view class="usertitle ellipsis">{{item.nickName}}</view>
						<view class="userid">ID:{{item.userId}}</view>
					</view>
				</view>
				<view class="usertime u-font-14">
					{{item.createdAt}}
				</view>

			</view> -->

			<!-- //加载提示 -->
			<view>
				<u-loadmore :status="loadStatus[current]" bgColor="#f2f2f2"></u-loadmore>
			</view>

		</view>



	</view>
</template>

<script>
	export default {
		name: 'team',
		data() {
			return {
				// #ifdef H5
				background: {
					backgroundColor: '#f33f5c'
				},
				// #endif

				dataList: [],
				list: [{
						name: '已注册',
						id: 1
					},
					{
						name: '已出单',
						id: 2
					},
					{
						name: '出多单',
						id: 3
					}
				], //tabs列表
				a: '直接团队',
				b: '间接团队',
				current: 0, //当前选中tabs
				page: 1,
				loadStatus: ['loadmore', 'loadmore'],
			};
		},
		onLoad() {
			this.getTeamsList()
		},

		// 上拉加载事件
		onReachBottom() {
			console.log("触发了到底")
			// if (this.loadStatus[this.current] == 'nomore') {
			// 	uni.showToast({
			// 		title: '没有更多了'
			// 	});
			// 	return;
			// }
			this.loadStatus[this.current] = 'loading';
			this.getTeamsList();

		},
		methods: {

			// tab栏切换
			clitbs(index) {
				this.loadStatus[this.current] = 'loadmore';
				this.current = index;
				this.page = 1;
				this.dataList = []
				this.getTeamsList()
			},
			// 获取下级
			getTeamsList() {

				const that = this
				const data = {
					lv: this.list[this.current].id,
					page: this.page
				}

				this.$http.user.getTeamsList(data)
					.then(res => {
						if (res.data) {
							that.page++;
							// that.list[0].name = that.a + '(' + res.data.lv_1_count + ')'
							// that.list[1].name = that.b + '(' + res.data.lv_2_count + ')'
							that.dataList = [...that.dataList, ...res.data]

							if (res.data.length < 20) {
								that.loadStatus[that.current] = 'nomore'
							}
						}
						console.log('获取下级', res)
					})
			},

		}
	}
</script>

<style scoped lang="scss">
	.team {
		height: calc(100vh - var(--window-top));
		background-color: $uni-bg-color;
		width: 100%;

		.tabs-box1 {
			color: #303133;
			position: sticky;
			top: var(--window-top);
			z-index: 99;
			background-color: #fff;
		}

		.page-box {
			.tb1 {
				background-color: #fff;
				font-size: 30rpx;
				padding: 20rpx 0;
				border: 1px solid rgba($color: #ccc, $alpha: 0.3);
			}

			.u-list-item {
				background-color: #ffffff;
				// font-size: 28rpx;
				// padding: 20rpx 40rpx 20rpx 60rpx;
				// border-bottom: 9px solid rgba($color: #ccc, $alpha: 0.3);

			}
			.usertitle {
				max-width: 260rpx;
				margin-top: -2px;
				font-size: 32rpx;
			}
			.userid {
				margin-top: 3px;
				font-size: 26rpx;
				color: #A0A0A0;
			}
			.usertime {
				color: #A0A0A0;
			}
		}
	}
</style>
